package GUILayer;
import ControlLayer.CtrOrder;
import ModelLayer.Order;
import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;

public class GUIOrder extends javax.swing.JFrame {
    private CtrOrder ctrOrder;

    public GUIOrder() {
        initComponents();
        ctrOrder = CtrOrder.getInstance();
        loadTableContent();
    }

    private void loadTableContent() {
        ((DefaultTableModel)tblOrderList.getModel()).setRowCount(0);
        ArrayList<Order> orderList = ctrOrder.getOrderList();
        for (Order order : orderList) {
            String discountIDs = new String();
            for (Integer discountID : order.getDiscountIDs()) {
                discountIDs += discountID + ", ";
            }
            ((DefaultTableModel)tblOrderList.getModel()).addRow(
                new Object [] {
                    order.getIDOrder(),
                    order.getIDCarrier(),
                    order.getIDLang(),
                    order.getIDCustomer(),
                    order.getIDCart(),
                    order.getIDCurrency(),
                    order.getIDAddressDelivery(),
                    order.getIDAddressInvoice(),
                    order.getSecureKey(),
                    order.getPayment(),
                    order.getModule(),
                    order.getRecyclable(),
                    order.getGift(),
                    order.getGiftMessage(),
                    order.getShippingNumber(),
                    order.getTotalDiscounts(),
                    order.getTotalPaid(),
                    order.getTotalPaidReal(),
                    order.getTotalProducts(),
                    order.getTotalShipping(),
                    order.getTotalWrapping(),
                    order.getInvoiceNumber(),
                    order.getDeliveryNumber(),
                    order.getInvoiceDate(),
                    order.getDeliveryDate(),
                    order.getValid(),
                    order.getDateAdd(),
                    order.getDateUpd(),
                    discountIDs
                }
            );
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scrlOrderList = new javax.swing.JScrollPane();
        tblOrderList = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tblOrderList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "id", "id_carrier", "id_lang", "id_customer", "id_cart", "id_currency", "id_address_delivery", "id_address_invoice", "secure_key", "payment", "module", "recyclable", "gift", "gift_message", "shipping_number", "total_discounts", "total_paid", "total_paid_real", "total_products", "total_shipping", "total_wrapping", "invoice_number", "delivery_number", "invoice_date", "delivery_date", "valid", "date_add", "date_upd", "discount IDs"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.Float.class, java.lang.Float.class, java.lang.Float.class, java.lang.Float.class, java.lang.Float.class, java.lang.Float.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Boolean.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        scrlOrderList.setViewportView(tblOrderList);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrlOrderList, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrlOrderList, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUIOrder().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane scrlOrderList;
    private javax.swing.JTable tblOrderList;
    // End of variables declaration//GEN-END:variables
}
